package com.masterrabbit.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.masterrabbit.common.log.annotation.Log;
import com.masterrabbit.common.log.enums.BusinessType;
import com.masterrabbit.common.security.annotation.RequiresPermissions;
import com.masterrabbit.domain.Services;
import com.masterrabbit.service.IServicesService;
import com.masterrabbit.common.core.web.controller.BaseController;
import com.masterrabbit.common.core.web.domain.AjaxResult;
import com.masterrabbit.common.core.utils.poi.ExcelUtil;
import com.masterrabbit.common.core.web.page.TableDataInfo;

/**
 * 服务项目Controller
 * 
 * @author laotu
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/services")
public class ServicesController extends BaseController
{
    @Autowired
    private IServicesService servicesService;

    /**
     * 查询服务项目列表
     */
    @RequiresPermissions("masterrabbit-kaixuan:services:list")
    @GetMapping("/list")
    public TableDataInfo list(Services services)
    {
        startPage();
        List<Services> list = servicesService.selectServicesList(services);
        return getDataTable(list);
    }

    /**
     * 导出服务项目列表
     */
    @RequiresPermissions("masterrabbit-kaixuan:services:export")
    @Log(title = "服务项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Services services)
    {
        List<Services> list = servicesService.selectServicesList(services);
        ExcelUtil<Services> util = new ExcelUtil<Services>(Services.class);
        util.exportExcel(response, list, "服务项目数据");
    }

    /**
     * 获取服务项目详细信息
     */
    @RequiresPermissions("masterrabbit-kaixuan:services:query")
    @GetMapping(value = "/{serviceId}")
    public AjaxResult getInfo(@PathVariable("serviceId") Long serviceId)
    {
        return success(servicesService.selectServicesByServiceId(serviceId));
    }

    /**
     * 新增服务项目
     */
    @RequiresPermissions("masterrabbit-kaixuan:services:add")
    @Log(title = "服务项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Services services)
    {
        return toAjax(servicesService.insertServices(services));
    }

    /**
     * 修改服务项目
     */
    @RequiresPermissions("masterrabbit-kaixuan:services:edit")
    @Log(title = "服务项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Services services)
    {
        return toAjax(servicesService.updateServices(services));
    }

    /**
     * 删除服务项目
     */
    @RequiresPermissions("masterrabbit-kaixuan:services:remove")
    @Log(title = "服务项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{serviceIds}")
    public AjaxResult remove(@PathVariable Long[] serviceIds)
    {
        return toAjax(servicesService.deleteServicesByServiceIds(serviceIds));
    }
}
